import globals from "globals"
import pluginJs from "@eslint/js"
import tseslint from "typescript-eslint"
import pluginVue from "eslint-plugin-vue"
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"
// import eslintAutoImport from "./.eslintrc-auto-import.json"

import { createRequire } from "module"
const require = createRequire(import.meta.url)
const eslintAutoImport = require("./.eslintrc-auto-import.json")

/** @type {import('eslint').Linter.Config[]} */
export default [
  { files: ["**/*.{js,mjs,cjs,ts,vue}"] },
  // 2.定义不同环境的全局变量
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
        ...eslintAutoImport.globals
      }
    }
  },
  // 3.js推荐规则
  pluginJs.configs.recommended,
  // 4.ts推荐规则
  ...tseslint.configs.recommended,
  // 5.vue推荐规则
  ...pluginVue.configs["flat/essential"],
  // 6.检测vue中的ts代码采⽤tsparser
  {
    files: ["**/*.vue"],
    languageOptions: { parserOptions: { parser: tseslint.parser } }
  },
  {
    ignores: ["*.css", "*.jpg", "*.jpeg", "*.png", "*.gif", "*.d.ts"]
  },
  // 增加测试规则
  {
    rules: {
      "no-console": "warn", // 将使⽤ `console` 的情况标记为警告
      "no-debugger": "warn", // 将使⽤ `debugger` 的情况标记为警告
      "no-var": "error", // 将使⽤ `var` 的情况标记为错误
      "prefer-const": "error", // 将使⽤ `let` 的情况标记为错误
      semi: ["error", "always"], // 强制分号
      "vue/multi-word-component-names": "off"
    }
  },
  eslintPluginPrettierRecommended
]
